using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using rbac.contracts.Dto.Input;
using rbac.contracts.Dto.Output;
using rbac.contracts.Interface;

namespace rbac.api.Controllers;
/// <summary>
/// 角色权限
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
[Authorize]
public class RolePermissionController:ControllerBase
{
    private readonly IRolePermissionService _rolePermissionService;

    public RolePermissionController(IRolePermissionService rolePermissionService)
    {
        _rolePermissionService = rolePermissionService;
    }

    /// <summary>
    /// 分配权限
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public Results<int> DistributePermission([FromBody] DistributeRolePermissionsInput input)
    {
        return Results<int>.DataResult(_rolePermissionService.DistributeRolePermission(input));
    }

    // api/rolePermission/GetPermissionByRoleId/3
    // api/controller/action/3
    /// <summary>
    /// 获取角色权限
    /// </summary>
    /// <param name="roleId"></param>
    /// <returns></returns>
    [HttpGet("{roleId}")]
    public Results<List<PermissionDto>> GetPermissionByRoleId(int roleId)
    {
        return Results<List<PermissionDto>>.DataResult(_rolePermissionService.GetPermissionByRoleId(roleId));
    }
}